from dataclasses import dataclass, field


@dataclass
class CaseInfo:
    # 必填
    feature: str
    story: str
    title: str
    request: dict
    validate: dict
    # 选填，通过赋值默认值来控制选填
    extract: dict = field(default_factory=lambda: {})
    parametrize: list = field(default_factory=lambda: [])


def verify_yaml(case_info: dict):
    """
    通过解包的方式，校验yaml格式是否正确
    :param case_info:
    :return:
    """
    try:
        case = CaseInfo(**case_info)
        return case
    except Exception as e:
        raise Exception(f"YAML测试用例不符合规范！{e}")
